import jwt
import datetime


from fuguangp9.settings import dev

key = dev.SECRET_KEY


class MyJwt:
    def getJwt(self, user, id):
        user1 = {
            'id': id,
            'account': user,
            'exp': datetime.datetime.now() + datetime.timedelta(hours=1)
        }

        return jwt.encode(user1, key,algorithm='HS256')

    def checktoken(self, token):
        if token:
            # try:
            return jwt.decode(token, key, algorithms=['HS256'])
            # except Exception:
            #     raise AuthenticationFailed("token不合法")


myjwt = MyJwt()
